﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace iPdf
{
    partial class SessionsManager : UserControl
    {
        public SessionsManager()
        {
            InitializeComponent();
        }

        public void AddSession(TataSession session)
        {
            this.SessionsGrid.AddSession(session);
        }

        private void SessionsManager_Load(object sender, EventArgs e)
        {
            this.SessionsGrid.Load();
            this.SessionsGrid.Selection.SelectionChanged += new SourceGrid.RangeRegionChangedEventHandler(this.sessionOperationToolStrip.SessionsGridSelection_SelectionChanged);
        }

        private void SessionsManager_VisibleChanged(object sender, EventArgs e)
        {
            if (!Elegant.Ui.Control.IsInDesignMode)
            {
                if (Visible && this.Parent.Visible)//make sure that it's actually visible
                {
                    string sessionsManagerTip = global::iPdf.Properties.Resources.SessionsManagerTip;
                    Global.ShowNotification(sessionsManagerTip);

                    this.sessionOperationToolStrip.Reset();

                    this.SessionsGrid.LoadSessions();

                    this.sessionOperationToolStrip.CellContext = new SourceGrid.CellContext(this.SessionsGrid, SourceGrid.Position.Empty);
                    this.sessionOperationToolStrip.UpdateToolStripButtons();
                }
            }
        }

        private void CloseButton_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void SessionOperationToolStrip_Searching(object sender, EventArgs e)
        {
            string searchText = this.sessionOperationToolStrip.SearchText;
            this.SessionsGrid.Search(searchText);

            this.sessionOperationToolStrip.UpdateToolStripButtons();
        }
    }
}
